package cn.edu.hnnu.a.rentacar.dao.hibernateimpl;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import cn.edu.hnnu.a.rentacar.beans.Cars;
import cn.edu.hnnu.a.rentacar.idao.ICarDAO;
import cn.edu.hnnu.a.rentacar.util.HibernateUtil;

public class CarDAOHibernateImpl implements ICarDAO {
	
	private static CarDAOHibernateImpl instance;
	
	private CarDAOHibernateImpl(){
		
	}
	
	public static CarDAOHibernateImpl getInstance(){
		if(null==instance){
			instance = new CarDAOHibernateImpl();
		}
		return instance;
	}

	@Override
	public void addCar(Cars car) {
		SessionFactory factory = HibernateUtil.getSessionFactory();
		Session session = factory.openSession();
		Transaction tran = session.beginTransaction();
		session.save(car);
		tran.commit();
		session.close();
	}

}
